package realQuestion.xinye;


//TODO:2023/9/19 交替打印ABCABC 十遍
public class Main1 {

    volatile  String  CODE="A";
    volatile int count_num=10;

    public  void printA(){
        synchronized (this){
            while (!CODE.equals("A")){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.print("A");
            CODE="B";
            notifyAll();
        }
    }
    public  void printB(){
        synchronized (this){
            while (!CODE.equals("B")){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            System.out.print("B");
            CODE="C";
            notifyAll();
        }
    }
    public  void printC(){
        synchronized (this){
            while (!CODE.equals("C")){
                try {
                    wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            System.out.print("C");
            CODE="A";
            notifyAll();
        }
    }

    public static void main(String[] args) {
        Main1 main1 = new Main1();
        for (int i = 0; i < main1.count_num; i++) {
            main1.printA();
            main1.printB();
            main1.printC();
        }
    }






}
